package io.ext;

import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ProtocolConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.ServiceConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ImportResource;

import io.ext.dubbo.SomeService;

@SpringBootApplication
@ImportResource("classpath:dubbo-config.xml")
public class DubboProvider
{



    public static void main( String[] args) throws InterruptedException {
        apiConfig();
        Object o = new Object();
        synchronized (o){
            o.wait();
        }
    }

    private void springConfig() {
        SpringApplication.run(DubboProvider.class);
    }
    private static void apiConfig() {
        ApplicationConfig  config =new ApplicationConfig();
        config.setName("fuck");
        RegistryConfig registryConfig = new RegistryConfig();
        registryConfig.setAddress("zookeeper://myserver:2181");

        ProtocolConfig protocol = new ProtocolConfig();
        protocol.setName("dubbo");
        protocol.setPort(12345);
        protocol.setThreads(10);

        ServiceConfig<SomeService> service = new ServiceConfig<>();
        service.setApplication(config);
        service.setRegistry(registryConfig);
        service.setInterface(SomeService.class);
        service.setProtocol(protocol);
        service.setRef(new SomeServiceImpl());
        service.export();
    }
}
